home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / src / Rkm_asm.lha / Assembly_Codes / OS_Sources / Libraries / SetFunction.s < prev    next >
Text File  |  1992-09-02  |  7KB  |  370 lines

  1.  
  2.  * This program simply changes the DisplayBeep() function, with a function
  3.  * that saves a Global Enviroment Variable in Ram:Env, before restoring the
  4.  * DisplayBeep() function back again.
  5.  
  6.     INCDIR    WORK:Include/
  7.  
  8.     INCLUDE    exec/exec_lib.i
  9.     INCLUDE    exec/memory.i
  10.     INCLUDE    intuition/intuition_lib.i
  11.     INCLUDE    intuition/intuition.i
  12.     INCLUDE dos/dos_lib.i
  13.     INCLUDE dos/dos.i
  14.     INCLUDE dos/dosextens.i
  15.     INCLUDE dos/var.i
  16.     INCLUDE    graphics/graphics_lib.i
  17.     INCLUDE    graphics/text.i
  18.     INCLUDE    workbench/icon_lib.i
  19.     INCLUDE    workbench/startup.i
  20.     INCLUDE    workbench/workbench.i
  21.  
  22. LIB_VER        EQU    39
  23. TRUE        EQU    -1
  24. FALSE        EQU    0
  25.  
  26.     lea    membuf(pc),a4
  27.  
  28.  * membuf (Memory Buffer) is set-up so that this code can be
  29.  * position-independant. The memory buffer contains the following
  30.  * addresses and their data:
  31.  *
  32.  *   0  Startup Return Message
  33.  *   4  _DOSBase
  34.  *   8  _IntuitionBase
  35.  *  12 _IconBase
  36.  *  16 Old Directory from CurrentDir()
  37.  *  20 Disk Object from GetDiskObject()
  38.  *  24 Argument addresses (30*4)
  39.  * 144 ReadArgs() return value
  40.  * 148 Task address
  41.  * 152 _GfxBase
  42.  * 156
  43.  * 160
  44.  * 164
  45.  * 165
  46.  * 166 Memory Buffer (12 bytes)
  47.  * 178
  48.  * 182 value 1 (for ToolType/CLI result)
  49.  * 183 value 2 (for ToolType/CLI result)
  50.  * 184
  51.  *
  52.  
  53.  * The Startup code below reads two CLI Arguments/WB ToolTypes as an example
  54.  * of how to programme CLI Arguments/WB ToolTypes.
  55.  *
  56.  * Note: The CLI Arguments/WB ToolTypes are done after Startup and Library
  57.  *       opening, so there is no use for the A0 pointer (which contains
  58.  *       pr_CLI).
  59.  
  60.     suba.l    a1,a1
  61.     move.l    4.w,a6
  62.     jsr    _LVOFindTask(a6)
  63.     tst.l    d0
  64.     beq    exit
  65.     move.l    d0,a5
  66.     move.l    a5,148(a4)
  67.     tst.l    pr_CLI(a5)        ; Was this task started from CLI?
  68.     bne.s    _main            ; Yes.
  69.     lea    pr_MsgPort(a5),a0    ; No. From Workbench.
  70.     jsr    _LVOWaitPort(a6)
  71.     lea    pr_MsgPort(a5),a0
  72.     jsr    _LVOGetMsg(a6)
  73.     move.l    d0,(a4)            ; D0 = A WBStartup Message.
  74.  
  75. _main
  76.     moveq    #LIB_VER,d0
  77.         lea     dos_name(pc),a1
  78.     move.l    4.w,a6
  79.         jsr    _LVOOpenLibrary(a6)
  80.         move.l  d0,4(a4)
  81.         beq     quit
  82.  
  83.         moveq    #LIB_VER,d0
  84.         lea     int_name(pc),a1
  85.         jsr    _LVOOpenLibrary(a6)
  86.         move.l  d0,8(a4)
  87.         beq     cl_dos
  88.  
  89.         moveq    #LIB_VER,d0
  90.         lea     gfx_name(pc),a1
  91.         jsr    _LVOOpenLibrary(a6)
  92.         move.l  d0,152(a4)
  93.         beq     cl_int
  94.  
  95.         moveq    #LIB_VER,d0
  96.         lea     icon_name(pc),a1
  97.         jsr    _LVOOpenLibrary(a6)
  98.         move.l  d0,12(a4)
  99.         beq     cl_gfx
  100.  
  101.  * Check the ToolTypes/CLI Arguments.
  102.  
  103.         move.l    (a4),a0
  104.         tst.l   a0
  105.         beq    fromcli
  106.     move.l    sm_ArgList(a0),a5
  107.         move.l  (a5),d1
  108.     beq    zero_args
  109.     move.l    4(a4),a6
  110.     jsr    _LVOCurrentDir(a6)
  111.         move.l  d0,16(a4)
  112.         move.l    wa_Name(a5),a0
  113.     move.l    12(a4),a6
  114.     jsr    _LVOGetDiskObject(a6)
  115.         move.l  d0,20(a4)
  116.         beq     zero_args
  117.         move.l    d0,a5
  118.         move.l  do_ToolTypes(a5),a5
  119.  
  120.     move.l    a5,a0
  121.         lea    ftstg0(pc),a1
  122.         jsr    _LVOFindToolType(a6)
  123.     tst.l    d0
  124.         beq.s    tt1
  125.     move.l    d0,a3
  126.     move.l    a3,a0
  127.     lea    mtstg0(pc),a1
  128.     jsr    _LVOMatchToolValue(a6)
  129.     tst.l    d0
  130.     beq.s    tto1
  131.     clr.b    182(a4)
  132.     bra.s    tt1
  133. tto1    move.l    a3,a0
  134.     lea    mtstg1(pc),a1
  135.     jsr    _LVOMatchToolValue(a6)
  136.     tst.l    d0
  137.     beq.s    tt1
  138.     move.b    #1,182(a4)
  139. tt1    move.l    a5,a0
  140.         lea    ftstg1(pc),a1
  141.         jsr    _LVOFindToolType(a6)
  142.     tst.l    d0
  143.         beq.s    tt2
  144.     move.l    d0,a3
  145.     move.l    a3,a0
  146.     lea    mtstg2(pc),a1
  147.     jsr    _LVOMatchToolValue(a6)
  148.     tst.l    d0
  149.     beq.s    tto2
  150.     clr.b    183(a4)
  151.     bra.s    tt2
  152. tto2    move.l    a3,a0
  153.     lea    mtstg3(pc),a1
  154.     jsr    _LVOMatchToolValue(a6)
  155.     tst.l    d0
  156.     beq.s    tto3
  157.     move.b    #1,183(a4)
  158.     bra.s    tt2
  159. tto3    move.l    a3,a0
  160.     lea    mtstg4(pc),a1
  161.     jsr    _LVOMatchToolValue(a6)
  162.     tst.l    d0
  163.     beq.s    tto4
  164.     move.b    #2,183(a4)
  165.     bra.s    tt2
  166. tto4    move.l    a3,a0
  167.     lea    mtstg5(pc),a1
  168.     jsr    _LVOMatchToolValue(a6)
  169.     tst.l    d0
  170.     beq.s    tt2
  171.     move.b    #3,183(a4)
  172. tt2
  173.     nop
  174.  
  175.  
  176. free_diskobj
  177.         move.l    20(a4),a0
  178.         jsr    _LVOFreeDiskObject(a6)
  179.     bra    zero_args
  180.  
  181. fromcli    lea    template(pc),a0
  182.     move.l  a0,d1
  183.         lea    24(a4),a5
  184.         move.l  a5,d2
  185.         moveq    #0,d3
  186.     move.l    4(a4),a6
  187.         jsr    _LVOReadArgs(a6)
  188.         move.l  d0,144(a4)
  189.         beq    zero_args
  190.  
  191.     move.l    (a5),a0
  192.     lea    mtstg0(pc),a1
  193.     bsr    cmpbyte
  194.     tst.l    d0
  195.     bne.s    cao1
  196.     clr.b    182(a4)
  197.     bra.s    ca1
  198. cao1    move.l    (a5),a0
  199.     lea    mtstg1(pc),a1
  200.     bsr    cmpbyte
  201.     tst.l    d0
  202.     bne.s    ca1
  203.     move.b    #1,182(a4)
  204. ca1    move.l    4(a5),a0
  205.     lea    mtstg2(pc),a1
  206.     bsr    cmpbyte
  207.     tst.l    d0
  208.     bne.s    cao2
  209.     clr.b    183(a4)
  210.     bra.s    ca2
  211. cao2    move.l    4(a5),a0
  212.     lea    mtstg3(pc),a1
  213.     bsr    cmpbyte
  214.     tst.l    d0
  215.     bne.s    cao3
  216.     move.b    #1,183(a4)
  217.     bra.s    ca2
  218. cao3    move.l    4(a5),a0
  219.     lea    mtstg4(pc),a1
  220.     bsr    cmpbyte
  221.     tst.l    d0
  222.     bne.s    cao4
  223.     move.b    #2,183(a4)
  224.     bra.s    ca2
  225. cao4    move.l    4(a5),a0
  226.     lea    mtstg5(pc),a1
  227.     bsr    cmpbyte
  228.     tst.l    d0
  229.     bne.s    ca2
  230.     move.b    #3,183(a4)
  231. ca2
  232.     nop
  233.  
  234.  
  235. free_cliargs
  236.         move.l    144(a4),d1
  237.         jsr    _LVOFreeArgs(a6)
  238.  
  239. zero_args
  240.  
  241.     move.l    4.w,a6
  242.     jsr    _LVOForbid(a6)
  243.     move.w    #_LVODisplayBeep,a0
  244.     lea    jwfunction(pc),a1
  245.     move.l    a1,d0
  246.     move.l    8(a4),a1
  247.     jsr    _LVOSetFunction(a6)
  248.     move.l    d0,a2
  249.     jsr    _LVOPermit(a6)
  250.  
  251.     moveq    #30,d1
  252.     move.l    4(a4),a6
  253.     jsr    _LVODelay(a6)
  254.  
  255.     suba.l    a0,a0
  256.     move.l    8(a4),a6
  257.     jsr    _LVODisplayBeep(a6)
  258.  
  259.     move.l    4.w,a6
  260.     jsr    _LVOForbid(a6)
  261.     movea.l    8(a4),a1
  262.     move.w    #_LVODisplayBeep,a0
  263.     move.l    a2,d0
  264.     jsr    _LVOSetFunction(a6)
  265.     jsr    _LVOForbid(a6)
  266.  
  267.     moveq    #30,d1
  268.     move.l    4(a4),a6
  269.     jsr    _LVODelay(a6)
  270.  
  271.     suba.l    a0,a0
  272.     move.l    8(a4),a6
  273.     jsr    _LVODisplayBeep(a6)
  274.  
  275. cl_icon    move.l  12(a4),a1
  276.     move.l    4.w,a6
  277.         jsr    _LVOCloseLibrary(a6)
  278.  
  279. cl_gfx    move.l  152(a4),a1
  280.     move.l    4.w,a6
  281.         jsr    _LVOCloseLibrary(a6)
  282.  
  283. cl_int    move.l  8(a4),a1
  284.     move.l    4.w,a6
  285.         jsr    _LVOCloseLibrary(a6)
  286.  
  287. cl_dos    move.l  4(a4),a1
  288.     move.l    4.w,a6
  289.         jsr    _LVOCloseLibrary(a6)
  290.  
  291. quit    move.l  #8000000,d0
  292.         moveq    #MEMF_CHIP,d1
  293.     move.l    4.w,a6
  294.     jsr    _LVOAllocMem(a6)
  295.     tst.l    d0
  296.     beq.s    cleanup
  297.     move.l    d0,a1
  298.     move.l    #8000000,d0
  299.     jsr    _LVOFreeMem(a6)
  300. cleanup    tst.l    (a4)
  301.     beq.s    exit            ; Exit - Task was started from CLI.
  302.     move.l    4.w,a6
  303.     jsr    _LVOForbid(a6)
  304.     move.l    (a4),a1            ; Reply to the WB Startup Message and
  305.     jsr    _LVOReplyMsg(a6)    ; Exit - Task was started from WB.
  306. exit    moveq    #0,d0
  307.     rts
  308.  
  309.  
  310.  * Sub-Routines.
  311.  
  312. jwfunction
  313.     move.l    #gev_name,d1
  314.     move.l    #gev_stg,d2
  315.     moveq    #23,d3
  316.     move.l    #GVF_GLOBAL_ONLY!GVF_BINARY_VAR,d4
  317.     move.l    4(a4),a6
  318.     jsr    _LVOSetVar(a6)
  319.     rts
  320.  
  321. cmpbyte    move.b  (a0)+,d0
  322.         move.b  (a1)+,d1
  323.         tst.b   d0
  324.         beq.s   byte0
  325.         cmp.b   d1,d0
  326.         beq.s   cmpbyte
  327. byte0    sub.b   d1,d0
  328.         ext.w   d0
  329.         ext.l   d0
  330.         rts
  331.  
  332. findlen    move.l    a0,a1
  333.     moveq    #0,d0
  334. not_nil    tst.b    (a1)+
  335.     beq.s    gotlen
  336.     addq.l    #1,d0
  337.     bra.s    not_nil
  338. gotlen    rts
  339.  
  340.  
  341.  * String Variables.
  342.  
  343. int_name    dc.b    'intuition.library',0
  344. dos_name    dc.b    'dos.library',0
  345. icon_name       dc.b    'icon.library',0,0
  346. gfx_name    dc.b    'graphics.library',0
  347. mtstg0        dc.b    'ARG_ONE',0
  348. mtstg1        dc.b    'ARG_TWO',0
  349. mtstg2        dc.b    'ARG_THREE',0
  350. mtstg3        dc.b    'ARG_FOUR',0,0
  351. mtstg4        dc.b    'ARG_FIVE',0,0
  352. mtstg5        dc.b    'ARG_SIX',0
  353. ftstg0          dc.b    'TOOLTYPE_ONE',0,0
  354. ftstg1          dc.b    'TOOLTYPE_TWO',0,0
  355. template    dc.b    'KEYWORD_ONE/K,KEYWORD_TWO/K',0
  356. gev_name    dc.b    'SetFunction',0
  357. gev_stg        dc.b    'Replaced DisplayBeep()',0,0
  358.  
  359.  
  360.  * Buffer Variables.
  361.  
  362. membuf        dcb.b    300,0
  363.  
  364.  
  365.     SECTION    VERSION,DATA
  366.  
  367.     dc.b    '$VER: Set_Function.s V1.01 (22.4.2001)',0
  368.  
  369.  
  370.     END